<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Setup and Installation Instructions &mdash; pyTunesConnect v1.0.1 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
          URL_ROOT:    '',
          VERSION:     '1.0.1',
          COLLAPSE_MODINDEX: false,
          FILE_SUFFIX: ''
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/interface.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="contents" title="Global table of contents" href="contents.html" />
    <link rel="index" title="Global index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="top" title="pyTunesConnect v1.0.1 documentation" href="index.html" />
    <link rel="next" title="Web Service Documentation" href="webservice.html" />
    <link rel="prev" title="Welcome to pyTunesConnect&#8217;s documentation!" href="index.html" />
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="webservice.html" title="Web Service Documentation"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Welcome to pyTunesConnect&#8217;s documentation!"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">pyTunesConnect v1.0.1 documentation</a> &raquo;</li>
      </ul>
    </div>
    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  
  <div class="section" id="setup-and-installation-instructions">
<h1 id="setup-and-installation-instructions">Setup and Installation Instructions<a class="headerlink" href="#setup-and-installation-instructions" title="Permalink to this headline">¶</a></h1>
<p>This section of the instructions will guide you through setting up pyTunesConnect to automatically download your sales reports on a daily basis and use the thin built in view layer to view your sales information.  The pytunesconnect class can easily be used on its own to pull data and when combined with the methods in pytunescharts.py you can easily integrate the graphs into your own systems.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">All of the setup instructions assume you are running a MySQL database on a Linux based machine with Python 2.x installed along with the latest version of the latest version of the MySQLdb module for Python installed.</p>
</div>
<div class="section" id="database-setup">
<h2 id="database-setup">Database Setup<a class="headerlink" href="#database-setup" title="Permalink to this headline">¶</a></h2>
<p>You will need to create a table with the following structure in your database:</p>
<pre> CREATE TABLE `daily` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`vendorid` varchar(64) NOT NULL,
`type` varchar(8) NOT NULL,
`units` int(11) NOT NULL,
`royaltyprice` float NOT NULL,
`begindate` date NOT NULL,
`enddate` date NOT NULL,
`customercurrency` varchar(8) NOT NULL,
`countrycode` varchar(4) NOT NULL,
`royaltycurrency` varchar(8) NOT NULL,
`appleidentifier` int(10) unsigned NOT NULL,
`customerprice` float NOT NULL,
PRIMARY KEY (`id`),
KEY `vendorid` (`vendorid`,`type`)
)</pre>
<p>You can name the table anything you want but be sure to change the name of dbtable in pytunesconnect.py if you do.</p>
</div>
<div class="section" id="customizing-settings">
<h2 id="customizing-settings">Customizing Settings<a class="headerlink" href="#customizing-settings" title="Permalink to this headline">¶</a></h2>
<p>Open the pytunesconnect folder that was extracted from the .zip file you downloaded.  Open the pytunesconnect.py file and find the section labeled &#8216;Default settings&#8217; at the top.  You will need to change some of these settings to fit your particular setup.</p>
<p>Once you have configured the settings properly you can upload all 3 of the files in the pytunesconnect folder to a location on your web server that will allow scripts to execute (cgi-bin is usually configured to allow this by default)</p>
<p>You should be able to test if everything is working by executing the following at the command line:</p>
<pre>python pytunesconnect.py -d itunesconnectuser itunesconnectpass</pre>
<p>Replace itunesconnectuser and itunesconnectpass with your itunesconnect username and password.  If something goes wrong an error should appear at the command line, otherwise you should see data in the MySQL table you created earlier with that days sales info.</p>
<p>If everything worked you will want to setup a daily cron to execute the above command which will automatically download your new sales data every day.  Sometime after 9:00am pacific time would be best as the sales reports usually go live for the previous day in the early hours of the morning.</p>
<p>An example entry in /etc/crontab to cause it to run every day at 10:50:</p>
<pre>50 10 * * * root /var/www/cgi-bin/stats/pytunesconnect.py -d itunesconnectuser password</pre>
<p>If you would like to pull data from multiple accounts into the same database table make multiple entries in the crontab for the different accounts.  This will cause all applications from multiple accounts to appear on the main menu.</p>
</div>
<div class="section" id="using-the-view-layer">
<h2 id="using-the-view-layer">Using the View Layer<a class="headerlink" href="#using-the-view-layer" title="Permalink to this headline">¶</a></h2>
<p>To use the built in view layer simply type in the path to the pytunesconnect.py file in your web browser, for example:</p>
<pre>http://www.mydomain.com/cgi-bin/pytunesconnect.py</pre>
<p>If everything was setup properly you should see the pyTunesConnect main menu which will provide a link for every application and in-app purchase in the database.  Clicking the link will take you to a page with detailed graphs showing the sales and download numbers.  If you would like to manually create links to these item details pages they are in the form of:</p>
<pre>http://www.mydomain.com/cgi-bin/pytunesconnect.py?action=itemdetail&amp;app=360706479</pre>
<p>Where app is the Apple ID of the application or IAP you are requesting details for.</p>
</div>
<div class="section" id="using-pytunesconnect-in-other-code">
<h2 id="using-pytunesconnect-in-other-code">Using pyTunesConnect in other code<a class="headerlink" href="#using-pytunesconnect-in-other-code" title="Permalink to this headline">¶</a></h2>
<p>pytunesconnect.py and pytunescharts.py were both written to be easily usable in other code.  It is easy to create an instance of the Pytunesconnect class and use it as a data source in other python code.  pytunescharts.py should be easily used in other python for generating the same graphs seen in the view layer that is built in to pyTunesConnect.</p>
<div class="section" id="example-using-the-pytunesconnect-class-as-a-data-source">
<h3 id="example-using-the-pytunesconnect-class-as-a-data-source">Example: Using the Pytunesconnect class as a data source<a class="headerlink" href="#example-using-the-pytunesconnect-class-as-a-data-source" title="Permalink to this headline">¶</a></h3>
<p>An instance of the Pytunesconnect class can easily be created in another python script to generate something like a CSV or to do more detail inspection of the date:</p>
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">pytunesconnect</span>
<span class="n">pytunes</span> <span class="o">=</span> <span class="n">pytunesconnect</span><span class="o">.</span><span class="n">Pytunesconnect</span><span class="p">(</span><span class="n">host</span><span class="o">=</span><span class="s">&quot;localhost&quot;</span><span class="p">,</span> <span class="n">user</span><span class="o">=</span><span class="s">&quot;root&quot;</span><span class="p">,</span> <span class="n">password</span><span class="o">=</span><span class="s">&quot;sekret&quot;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&quot;sales_data&quot;</span><span class="p">,</span> <span class="n">table</span><span class="o">=</span><span class="s">&quot;daily&quot;</span><span class="p">)</span>
<span class="n">appleIdOfMyApplication</span> <span class="o">=</span> <span class="s">&quot;1234567&quot;</span>
<span class="n">CSVFilePath</span> <span class="o">=</span> <span class="s">&quot;/tmp/salesDataCSV.txt&quot;</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">pytunes</span><span class="o">.</span><span class="n">getItemDetail</span><span class="p">(</span><span class="n">appleIdOfMyApplication</span><span class="p">)</span>
<span class="c">#for example data might be a list that looks like this: [[&quot;Date&quot;, &quot;NewDownloads&quot;, &quot;Reinstalls&quot;],[&quot;2010-02-22&quot;, &quot;200&quot;, &quot;50&quot;],[&quot;2010-02-23&quot;, &quot;150&quot;, &quot;25&quot;]]</span>
<span class="nb">file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">CSVFilePath</span><span class="p">,</span> <span class="s">&quot;w&quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">data</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">column</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
                <span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">column</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot;,&quot;</span><span class="p">)</span>
        <span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">)</span>
<span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
<p>You should now have a CSV of the sales data for that item located at /tmp/salesDataCSV.txt.  There are endless possibilities for using it as a data source.</p>
</div>
<div class="section" id="example-using-the-web-service-in-a-php-page">
<h3 id="example-using-the-web-service-in-a-php-page">Example: Using the web service in a PHP page<a class="headerlink" href="#example-using-the-web-service-in-a-php-page" title="Permalink to this headline">¶</a></h3>
<p>If you want to include one of the charts in a PHP page it is fairly easy to do, just be sure the IP address of the web server that will be executing the PHP is in the list of allowed IP addresses in pytunesconnect.py:</p>
<pre>&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;Welcome to my webpage!&lt;/title&gt;
  &lt;script type="text/javascript" src="http://danvk.org/dygraphs/dygraph-combined.js"&gt;&lt;/script&gt;
 &lt;/head&gt;
 &lt;body&gt;
  Welcome to my iPhone App's webpage, check out the graph of our sales over the last 7 days below!&lt;br&gt;
  &lt;?php
   $curl_handle=curl_init();
   curl_setopt($curl_handle,CURLOPT_URL,'http://www.mydomain.com/cgi-bin/pytunesconnect.py?action=dlchartapi&amp;app=359232243&amp;type=new&amp;offset=7');
   $buffer = curl_exec($curl_handle);
   curl_close($curl_handle);

   if (empty($buffer))
   {
    echo "Sorry, there was an error getting the chart.&lt;p&gt;";
   }
   else
   {
    echo $buffer;
   }
  ?&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3>Table Of Contents</h3>
            <ul>
<li><a class="reference external" href="">Setup and Installation Instructions</a><ul>
<li><a class="reference external" href="#database-setup">Database Setup</a></li>
<li><a class="reference external" href="#customizing-settings">Customizing Settings</a></li>
<li><a class="reference external" href="#using-the-view-layer">Using the View Layer</a></li>
<li><a class="reference external" href="#using-pytunesconnect-in-other-code">Using pyTunesConnect in other code</a><ul>
<li><a class="reference external" href="#example-using-the-pytunesconnect-class-as-a-data-source">Example: Using the Pytunesconnect class as a data source</a></li>
<li><a class="reference external" href="#example-using-the-web-service-in-a-php-page">Example: Using the web service in a PHP page</a></li>
</ul>
</li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="index.html" title="previous chapter">Welcome to pyTunesConnect&#8217;s documentation!</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="webservice.html" title="next chapter">Web Service Documentation</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/setup.txt">Show Source</a></li>
            </ul>
            <h3>Quick search</h3>
            <form class="search" action="search.html" method="get">
              <input type="text" name="q" size="18" /> <input type="submit" value="Go" />
              <input type="hidden" name="check_keywords" value="yes" />
              <input type="hidden" name="area" value="default" />
            </form>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="webservice.html" title="Web Service Documentation"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Welcome to pyTunesConnect&#8217;s documentation!"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">pyTunesConnect v1.0.1 documentation</a> &raquo;</li>
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2010, Jonathan Carroll.
      Last updated on May 06, 2010.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
    </div>
  </body>
</html>